package com.tdkj.service.information.impl;

import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.tdkj.dao.information.IBeanInfoModuleDao;
import com.tdkj.dao.information.IBeanModuleColumnDao;
import com.tdkj.model.base.BaseEntity;
import com.tdkj.model.information.BeanInfoModule;
import com.tdkj.model.information.BeanModuleColumn;
import com.tdkj.service.BaseService;
import com.tdkj.service.information.IBeanInfoModuleService;
@Component("infoModuleService")
public class BeanInforModuleImpl extends BaseService implements IBeanInfoModuleService{
	private IBeanInfoModuleDao beanInforModuleDao;
	private IBeanModuleColumnDao beanModuleColumnDao;

	public IBeanModuleColumnDao getBeanModuleColumnDao() {
		return beanModuleColumnDao;
	}
	@Resource
	public void setBeanModuleColumnDao(IBeanModuleColumnDao beanModuleColumnDao) {
		this.beanModuleColumnDao = beanModuleColumnDao;
	}
	public IBeanInfoModuleDao getBeanInforModuleDao() {
		return beanInforModuleDao;
	}

	@Resource
	public void setBeanInforModuleDao(IBeanInfoModuleDao beanInforModuleDao) {
		this.beanInforModuleDao = beanInforModuleDao;
	}
	@Override
	public void deleteColumn(long columnId) {
		// TODO Auto-generated method stub
		BeanModuleColumn bean=beanModuleColumnDao.findById(columnId, BeanModuleColumn.class);
		beanModuleColumnDao.delete(bean);
	}
	@Override
	public void updateColumn(BeanModuleColumn column) {
		// TODO Auto-generated method stub
		//BeanModuleColumn bean=beanModuleColumnDao.findById(column.getId(), BeanModuleColumn.class);
		System.out.println(column.getId());
		beanModuleColumnDao.merge(column);
	}
	@Override
	public BeanModuleColumn findModuleColumn(long columnId) {
		// TODO Auto-generated method stub
		BeanModuleColumn bean=beanModuleColumnDao.findById(columnId, BeanModuleColumn.class);
		return bean;
	}
	@Override
	public List<BeanModuleColumn> findModuleColumns(long moduleId) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void saveModuleColumn(long moduleId, BeanModuleColumn column) {
		// TODO Auto-generated method stub
		BeanInfoModule inforModule=beanInforModuleDao.findById(moduleId, BeanInfoModule.class);
		column.setInforModule(inforModule);
		beanModuleColumnDao.save(column);
		
	}
	@Override
	public void saveModuleColumns(long moduleId, List<BeanModuleColumn> columns) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void deleteModule(long moduleId) {
		// TODO Auto-generated method stub
		BeanInfoModule inforModule=beanInforModuleDao.findById(moduleId, BeanInfoModule.class);
		beanInforModuleDao.delete(inforModule);
	}
	@Override
	public void updateModule(long id,String name) {
		// TODO Auto-generated method stub
		BeanInfoModule bean=beanInforModuleDao.findById(id, BeanInfoModule.class);
		bean.setModulename(name);
	}
	@Override
	public BeanModuleColumn findModuleColumn(String mt, String ct) {
		// TODO Auto-generated method stub
		BeanInfoModule mbean=new BeanInfoModule();
		mbean.setModuletype(mt);
		List<BeanInfoModule> list=beanInforModuleDao.findByExample(mbean);
		if(list.size()>=1){
			BeanInfoModule bean=list.get(0);
			List<BeanModuleColumn> cList=bean.getModuleColumns();
			if(cList.size()>=1){
				for (int i = 0; i < cList.size(); i++) {
					BeanModuleColumn cBean=cList.get(i);
					if(cBean.getColumntype().equals(ct)){
						return cBean;
					}
				}
			}
		}
		return null;
	}
}
